const { findOneSiteService, createSiteService } = require("../../service/site");
const { ErrorRes, SuccessRes } = require("../../res-model/index");
const {
  createSiteFailInfo,
  findOneSiteFailInfo,
} = require("../../res-model/failInfo/sites");
/**
 * 查询所有导航
 */
async function findOneSite() {
  let sites;
  try {
    sites = await findOneSiteService();
  } catch (ex) {
    console.error("查询网站配置信息", ex);
    return new ErrorRes(findOneSiteFailInfo); // 数据库错误
  }
  // 查询失败
  if (sites == null)
    return new ErrorRes(findOneSiteFailInfo, "网站配置信息数据不存在");

  // 查询成功
  return new SuccessRes(sites);
}
/**
 * @description 创建网站配置
 * @returns
 */
async function createSite() {
  let newSite;
  try {
    newSite = await createSiteService();
  } catch (ex) {
    console.error("创建网站配置错误", ex);
    return new ErrorRes(createSiteFailInfo); // 数据库错误
  }
  // 创建失败
  if (newSite == null)
    return new ErrorRes(createSiteFailInfo, "创建网站配置信息错误");

  // 创建成功
  return new SuccessRes(newSite);
}
module.exports = {
  findOneSite,
  createSite,
};
